import numpy as np
import matplotlib.pyplot as plt
#plt.figure (figsize = (15 ,18))
%matplotlib inline
#plt.figure (figsize = (15 ,18))
plt.rcParams['figure.figsize']=(20,10)
#for n in [10, 20, 50, 100, 500, 2000]:
# s = np.random.randint(1,7,n)
#print(s)
#hist, bins, patches = plt.hist(s, bins=[1, 2, 3, 4,5,6,7])
#plt.show()
#labels = '1', '2', '3', '4', '5','6'
#explode = (0.1, 0, 0, 0, 0, 0)
#plt.pie(hist, explode=explode, labels=labels, autopct='%1.1f%%',shadow=True,startangle=90)
#plt.axis('equal')
#plt.show()
# plt.show()
#Determine les proportion des valeurs avec la fonction his
Xmin=[]
Xmax=[]
Xsd =[]
Dff = []
for n in [10, 20, 50, 100, 500, 2000]:
s = np.random.randint(1,7,n)
print(n)
#hist, bins, patches = plt.hist(s, bins=[1, 2, 3, 4, 5, 6, 7],normed=True)
hist = np.histogram(s, bins=[1, 2, 3, 4, 5, 6, 7],normed=True)
#print(hist)
Xmin.append(min(hist[0]))
Xmax.append(max(hist[0]))
Xsd.append(np.std(hist[0]))
#print(hist)
#plt.xlabel('Classes')
# plt.ylabel('Pourcentage des classes')
# plt.show()
labels = '1', '2', '3', '4', '5','6'
explode = (0.1, 0, 0, 0, 0, 0)
plt.pie(hist[0], explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal')
plt.xlabel('% minimum: {0}; % maximum : {1}; Difference: {2}; Ecartype: {3}'.format(min(hist[0]),
max(hist[0]), max(hist[0])-min(hist[0]), np.std(hist[0])))
plt.show()
1.1 ) Simulation de quelques jeus de données
N= 10 donnees de lois N(0,1)
mu=0
sigma= 1 # l'ecartype
X_a = np.random.normal(mu, sigma, 10)
print(X_a)
N= 10 donnees de lois U([0,1])
X_b = np.random.uniform(0,1,10)
print(X_b)
1.2) Simulation d'un jeu de 500 données selon une loi N(3,5) puis selon une loi U(3,5)
X_1 = np.random.normal(3,5,500)
#print(X_1)
un histogramme des données brutes avec la fonction hist de matplotlib.pyplot
#import pylab as plt
count, bins, patches = plt.hist(X_1, 30)
#plt.xlabel('histogramme des données brutes')
#plt.show()
#plt.xticks(fontsize=14)
#plt.yticks(fontsize=14)
un histogramme normalisé (à l’aide la même fonction)
count, bins, patches = plt.hist(X_1, 30,normed=True)
X_2 = np.random.uniform(5,3,500)
#print(X_2)
un histogramme des données brutes avec la fonction hist de matplotlib.pyplot
count, bins, patches = plt.hist(X_2, 30)
un histogramme normalisé (à l’aide la même fonction)
count, bins, patches = plt.hist(X_2, 30,normed=True)
from scipy.stats import norm
count, bins, patches = plt.hist(X_1, 30,normed=True)
#print(X_1)
#norm.pdf(X_1)
Xpdf=np.linspace(-15,15,100)
#X_1.sort()
#mesX=X_1
plt.plot(Xpdf, norm.pdf(Xpdf, np.mean(X_1),np.std(X_1) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdf, norm.pdf(Xpdf,loc=3,scale=np.sqrt(5)) , linewidth=2, color='r', label='norm pdf' )
from scipy.stats import uniform
count, bins, patches = plt.hist(X_2, 30,normed=True)
#print(X_1)
#norm.pdf(X_1)
Xpdfu=np.linspace(3,5,100)
#X_1.sort()
#mesX=X_1
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r' , label='uniform pdf')
plt.show()
p=10, n=5
X5_bar = []
for p in range(1,11) :
X_i = np.random.uniform(5,3,5)
x_bar = np.mean(X_i)
X5_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
#print(np.mean(X_i))
#plt.plot(Xpdf, uniform.pdf(Xpdfu, np.mean(X_i),np.std(X_i) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.xlabel('X_i plot')
plt.show()
The plot for X_bar gives :
print(X5_bar)
count, bins, patches = plt.hist(X5_bar,normed=True, color='g')
plt.xlabel('X_bar plot pour n=5')
plt.show()
p = 10, n = 50
X50_bar = []
for p in range(1,11) :
X_i = np.random.uniform(5,3,50)
x_bar = np.mean(X_i)
X50_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.show()
The plot for X_bar gives :
print(X50_bar)
count, bins, patches = plt.hist(X50_bar,normed=True, color='g')
plt.xlabel('X_bar plot for n=50')
plt.show()
p = 10, n = 500
X500_bar = []
for p in range(1,11) :
X_i = np.random.uniform(5,3,500)
x_bar = np.mean(X_i)
X500_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.show()
print(X500_bar)
count, bins, patches = plt.hist(X500_bar,normed=True, color='g')
plt.xlabel('X_bar plot for n=500')
plt.show()
p = 200, n = 5
X5_bar = []
for p in range(1,201) :
X_i = np.random.uniform(5,3,5)
x_bar = np.mean(X_i)
X5_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
#print(np.mean(X_i))
#plt.plot(Xpdf, uniform.pdf(Xpdfu, np.mean(X_i),np.std(X_i) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.xlabel('X_i plot')
plt.show()
#print(X5_bar)
count, bins, patches = plt.hist(X5_bar,normed=True, color='g')
plt.xlabel('X_bar plot pour p= 200 n = 5')
plt.show()
p=200, n= 50
X50_bar = []
for p in range(1,201) :
X_i = np.random.uniform(5,3,50)
x_bar = np.mean(X_i)
X50_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
#print(np.mean(X_i))
#plt.plot(Xpdf, uniform.pdf(Xpdfu, np.mean(X_i),np.std(X_i) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.xlabel('X_i plot')
plt.show()
#print(X50_bar)
count, bins, patches = plt.hist(X50_bar,normed=True, color='g')
plt.xlabel('X_bar plot pour p = 200, n = 50')
plt.show()
p = 200, n = 500
X500_bar = []
for p in range(1,201) :
X_i = np.random.uniform(5,3,500)
x_bar = np.mean(X_i)
X500_bar.append(x_bar)
count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
#print(np.mean(X_i))
#plt.plot(Xpdf, uniform.pdf(Xpdfu, np.mean(X_i),np.std(X_i) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.xlabel('X_i plot')
plt.show()
#print(X500_bar)
count, bins, patches = plt.hist(X500_bar,normed=True, color='g')
plt.xlabel('X_bar plot pour p = 200, n = 500')
plt.show()
n = 10
Xn_bar = []
for i in [ 5, 10, 20, 30, 40, 50, 100, 200, 500, 1000, 2000, 5000]:
for p in range(1, i+1) :
X_i = np.random.uniform(5,3,n)
x_bar = np.mean(X_i)
Xn_bar.append(x_bar)
#count, bins, patches = plt.hist(X_i,normed=True)
Xpdfu=np.linspace(3,5,100)
plt.plot(Xpdf, norm.pdf(Xpdf, np.mean(X_i),np.std(X_i) ), linewidth=2, color='g', label='norm pdf' )
plt.plot(Xpdfu, uniform.pdf(Xpdfu,loc=3,scale=2) , linewidth=2, color='r')
plt.show()
import pandas as pd
#df = pd.read_table('/home/foutse/Desktop/TPA_MasterTried/pluie.txt',sep = ' ', header= None) #=('Years','Zone 1', 'Zone 2', 'Zone 3', 'Zone 4'))
#data = pd.read_csv('/home/foutse/Desktop/TPA_MasterTried/pluie.txt', names=['Years','Zone 1', 'Zone 2', 'Zone 3', 'Zone 4'])
df = pd.read_csv('/home/foutse/Desktop/TPA_MasterTried/pluie.txt', sep = ' ', engine='python', header= None)
df.columns = ['Years','Zone1', 'Zone2', 'Zone3', 'Zone4']
print(df)
table_mean = [df['Zone1'].mean(), df['Zone2'].mean(), df['Zone3'].mean(), df['Zone4'].mean()]
table_min = [df['Zone1'].min(), df['Zone2'].min(), df['Zone3'].min(), df['Zone4'].min()]
table_max = [df['Zone1'].max(), df['Zone2'].max(), df['Zone3'].max(), df['Zone4'].max()]
table_std = [df['Zone1'].std(), df['Zone2'].std(), df['Zone3'].std(), df['Zone4'].std()]
table_etendu = [df['Zone1'].max() - df['Zone1'].min(),df['Zone2'].max() - df['Zone2'].min(), df['Zone3'].max() - df['Zone3'].min(), df['Zone4'].max() - df['Zone4'].min()]
print('the mean is:', table_mean)
print('the max is:',table_max)
print('the min is:',table_min)
print('the std is:',table_std)
print('the etendu is:',table_etendu)
b = {'Zone1': [table_mean[0], table_max[0], table_min[0],table_std[0], table_etendu[0]],'Zone2': [table_mean[1], table_max[1], table_min[1],table_std[1], table_etendu[1]],'Zone3': [table_mean[2], table_max[2], table_min[2],table_std[2], table_etendu[2]],'Zone4': [table_mean[3], table_max[3], table_min[3],table_std[3], table_etendu[3]]}
dataT = pd.DataFrame(data = b)
dataT.index = ['Moyenne','Maximum','Minimum','l’écart type','l’étendue']
dataT
#print(df["Zone3"])
plt.plot (df['Years'] , df["Zone1"] , color = "cyan", label = 'Zone1')
plt.plot (df['Years'] , df["Zone2"] , color = "red", label = 'Zone2')
plt.plot (df['Years'] , df["Zone3"] , color = "magenta", label = 'Zone3')
plt.plot (df['Years'] , df["Zone4"] , color = "green", label = 'Zone4')
plt.legend(loc='best')
plt.title('Figure des courbes de chaque variable')
plt.xlabel('Annees')
#plt.ylabel('donnees')
#plt.ylabel('donnees')
#plt.ylabel('Anneés')
#plt.xlabel('donnees')
plt.show()
MEs_Z1 = table_mean[0] + table_std[0]
MEs_Z2 = table_mean[1] + table_std[1]
MEs_Z3 = table_mean[2] + table_std[2]
MEs_Z4 = table_mean[3] + table_std[3]
MEd_Z1 = table_mean[0] - table_std[0]
MEd_Z2 = table_mean[1] - table_std[1]
MEd_Z3 = table_mean[2] - table_std[2]
MEd_Z4 = table_mean[3] - table_std[3]
#print(ME)
plt.plot (df['Years'] , df["Zone1"] , color = "cyan")
plt.axhline( MEs_Z1 , color = "blue", label = 'moyenne + ecart type')
plt.axhline( MEd_Z1 , color = "red", label = 'moyenne - ecart type')
plt.axhline( table_mean[0] , color = "green", label = 'Moyenne')
plt.legend(loc='upper right')
plt.title('Figure des courbes de la Zone 1')
plt.xlabel('Annees')
#plt.figure (figsize = (25 ,30))
plt.show()
plt.plot (df['Years'] , df["Zone2"] , color = "cyan")
plt.axhline( MEs_Z2 , color = "blue", label = 'moyenne + ecart type')
plt.axhline( MEd_Z2 , color = "red", label = 'moyenne - ecart type')
plt.axhline( table_mean[1] , color = "green", label = 'Moyenne')
plt.legend(loc='best')
plt.title('Figure des courbes de la Zone 2')
plt.xlabel('Annees')
plt.show()
plt.plot (df['Years'] , df["Zone3"] , color = "cyan")
plt.axhline( MEs_Z3 , color = "blue", label = 'moyenne + ecart type')
plt.axhline( MEd_Z3 , color = "red", label = 'moyenne - ecart type')
plt.axhline( table_mean[2] , color = "green", label = 'Moyenne')
plt.legend(loc='best')
plt.title('Figure des courbes de la Zone 3')
plt.xlabel('Annees')
plt.show()
plt.plot (df['Years'] , df["Zone4"] , color = "cyan")
plt.axhline( MEs_Z4 , color = "blue", label = 'moyenne + ecart type')
plt.axhline( MEd_Z4 , color = "red", label = 'moyenne - ecart type')
plt.axhline( table_mean[3] , color = "green", label = 'Moyenne')
plt.legend(loc='best')
plt.title('Figure des courbes de la Zone 4')
plt.xlabel('Annees')
plt.show()
Q1_Z1 = round(np.percentile(df["Zone1"], 25))
Q2_Z1 = round(np.percentile(df["Zone1"], 50)) # return 50th percentile, e.g median.
Q3_Z1 = round(np.percentile(df["Zone1"], 75))
print('Q1 de Z1:',Q1_Z1)
print('Q2 de Z1:',Q2_Z1)
print('Q3 de Z1:',Q3_Z1)
Q1_Z2 = round(np.percentile(df["Zone2"], 25))
Q2_Z2 = round(np.percentile(df["Zone2"], 50) )# return 50th percentile, e.g median.
Q3_Z2 = round(np.percentile(df["Zone2"], 75))
print('Q1 de Z2:',Q1_Z2)
print('Q2 de Z2:',Q2_Z2)
print('Q3 de Z2:',Q3_Z2)
Q1_Z3 = round(np.percentile(df["Zone3"], 25))
Q2_Z3 = round(np.percentile(df["Zone3"], 50) )# return 50th percentile, e.g median.
Q3_Z3 = round(np.percentile(df["Zone3"], 75))
print('Q1 de Z3:',Q1_Z3)
print('Q2 de Z3:',Q2_Z3)
print('Q3 de Z3:',Q3_Z3)
Q1_Z4 = round(np.percentile(df["Zone4"], 25))
Q2_Z4 = round(np.percentile(df["Zone4"], 50) )# return 50th percentile, e.g median.
Q3_Z4 = round(np.percentile(df["Zone4"], 75))
print('Q1 de Z4:',Q1_Z4)
print('Q2 de Z4:',Q2_Z4)
print('Q3 de Z4:',Q3_Z4)
q = {'Zone1': [Q1_Z1, Q2_Z1, Q3_Z1, Q3_Z1 - Q1_Z1 ],'Zone2': [Q1_Z2, Q2_Z2, Q3_Z2,Q3_Z2 - Q1_Z2 ],'Zone3': [Q1_Z3, Q2_Z3, Q3_Z3, Q3_Z3 - Q1_Z3],'Zone4': [Q1_Z4,Q2_Z4,Q3_Z4, Q3_Z4 - Q1_Z4]}
Q_table = pd.DataFrame(data = q)
Q_table.index = ['Q1','Q2','Q3', 'Q3 - Q1']
Q_table
plt.boxplot([df["Zone1"],df["Zone2"],df["Zone3"],df["Zone4"]], whis = 'range')
plt.title('boxplot avec sequence')
#plt.boxplot(df["Zone2"])
#plt.boxplot(df["Zone3"])
#plt.boxplot(df["Zone4"])